#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int help(int n) {
	int i = sqrt(n);
	while (n%i) 
		i--;
	return i == 1 ? n : max(help(i), help(n / i));
}
int main(){
    int m;
    cin>>m;
    while(m--){
    string str = "";
	cin >> str;
	int n = 0;
	for (auto ch : str)
		if (isdigit(ch))
			n = n * 10 + ch - '0';
	cout << (n? help(n):0)<<endl; 
    }
}